package com.cskaoyan.catmall.controller.wx;

import com.cskaoyan.catmall.model.bo.WxCommentBo;
import com.cskaoyan.catmall.model.bo.WxOrderSubmitBo;
import com.cskaoyan.catmall.model.pojo.MarketOrderGoods;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.WxOrderGoodsDetailVo;
import com.cskaoyan.catmall.model.vo.WxOrderListVo;
import com.cskaoyan.catmall.model.vo.WxOrderSubmitVo;
import com.cskaoyan.catmall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 前台订单模块
 * 创建日期: 2022/01/11 00:27
 *
 * @author ghr
 */
@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    OrderService orderService;

    /**
     * @param showType
     * @param page
     * @param limit
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序订单列表
     * @author ghr
     * @date 2022/1/11 4:04 下午
     */
    @RequestMapping("list")
    public BaseRespVo list(Integer showType, Integer page, Integer limit) {
        WxOrderListVo wxOrderListVo = orderService.selectOrderList(showType, page, limit);
        return BaseRespVo.ok(wxOrderListVo);
    }

    /**
     * @param
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序取消订单
     * @author ghr
     * @date 2022/1/11 10:28 上午
     */
    @PostMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.cancelOrder(orderId);
        return BaseRespVo.ok();
    }

    /**
     * @param
     * @param orderId
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序订单申请退款
     * @author ghr
     * @date 2022/1/11 10:47 上午
     */
    @PostMapping("refund")
    public BaseRespVo refund(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.refundOrder(orderId);
        return BaseRespVo.ok();
    }

    /**
     * @param map
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序订单已收货
     * @author ghr
     * @date 2022/1/11 10:59 上午
     */
    @PostMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.confirmOrder(orderId);
        return BaseRespVo.ok();
    }

    /**
     * @param orderId
     * @param goodsId
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序评价页面
     * @author ghr
     * @date 2022/1/11 11:12 上午
     */
    @GetMapping("goods")
    public BaseRespVo goods(Integer orderId, Integer goodsId) {
        MarketOrderGoods marketOrderGoods = orderService.goods(orderId, goodsId);
        return BaseRespVo.ok(marketOrderGoods);
    }

    /**
     * @param
     * @param wxCommentBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序评价
     * @author ghr
     * @date 2022/1/11 1:16 下午
     */
    @PostMapping("comment")
    public BaseRespVo comment(@RequestBody WxCommentBo wxCommentBo) {
        orderService.orderComment(wxCommentBo);
        return BaseRespVo.ok();
    }

    /**
     * @param
     * @param orderId
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 小程序删除订单
     * @author ghr
     * @date 2022/1/11 1:22 下午
     */
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        orderService.deleteOrderById(orderId);
        return BaseRespVo.ok();
    }

    /**
     * @param
     * @param orderId
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 订单细节
     * @author ghr
     * @date 2022/1/11 8:44 下午
     */
    @GetMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        WxOrderGoodsDetailVo detailVo = orderService.detail(orderId);
        return BaseRespVo.ok(detailVo);
    }

    /**
     * @param
     * @param orderId
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 订单不能支付
     * @author ghr
     * @date 2022/1/12 1:13 下午
     */
    //TODO 订单不能支付
    @PostMapping("prepay")
    public BaseRespVo prepay(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        return BaseRespVo.fail("订单不能支付");
    }

    /**
     * @description 订单确认
     * @author ghr
     * @date 2022/1/12 8:48 下午
     * @param
     * @param submitBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     */
    @PostMapping("submit")
    public BaseRespVo submit(@RequestBody WxOrderSubmitBo submitBo) {
        WxOrderSubmitVo submitVo = orderService.submit(submitBo);
        return BaseRespVo.ok();
    }
}